package net3;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class MultiThreadTcpServer {

    private static final int PORT = 4090;
    public static void main(String[] args) throws IOException, InterruptedException {
        ServerSocket socket = new ServerSocket(PORT);
        System.out.println("服务器已经启动...");
        System.out.println("---------------");
        while (true) {
            Thread thread = new Thread(() -> {
                try {
                    System.out.println("正在等待客户端请求...");
                    Socket client = socket.accept();
                    process(client);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            });
            thread.start();
        }
    }

    private static void process (Socket client) throws IOException {
        System.out.println("已收到客户端：" + client.getPort() + "请求");
        System.out.println("---------------------");
        client.close();
    }

}
